﻿Imports System.IO
Public Class ATRASOS
    Dim TJUROS As String
    Dim VJUROS As String
    Public Sub Gravar(ByVal New01 As String)
        Try
            Dim Nome_Arquivo As String = String.Format("{0}\Logs\{1}.txt", "\\SERVIDOR1\Publico Administrativo\Público Administrativo\antigo", FormatDateTime(Date.Today, DateFormat.ShortDate).Replace("/", "").ToString)
            If Not Directory.Exists("\\SERVIDOR1\Publico Administrativo\Público Administrativo\antigo" & "\Logs\") Then
                Directory.CreateDirectory("\\SERVIDOR1\Publico Administrativo\Público Administrativo\antigo" & "\Logs\")
            End If
            Using fs As FileStream = New FileStream(Nome_Arquivo, FileMode.OpenOrCreate, FileAccess.ReadWrite)
                Dim s As StreamWriter = New StreamWriter(fs)
                s.Close()
            End Using
            Using File As FileStream = New FileStream(Nome_Arquivo, FileMode.Append, FileAccess.Write)
                Using sw As StreamWriter = New StreamWriter(File)
                    sw.Write("Data/Hora: " & DateTime.Now.ToString() & vbCrLf)
                    sw.Write("Por: " & LoginForm3.loginTextBox.Text & vbCrLf)
                    sw.Write("" & vbCrLf)
                    sw.Write("Mensagem: " & New01 & vbCrLf)
                    sw.Write("==============================================" & _
               "==============================================" & _
               "==============================================" & vbCrLf)
                End Using
            End Using
        Catch EX As Exception
            MsgBox("ERRO AO GERAR O ARQUIVO DE LOG " & EX.ToString)
        End Try
    End Sub
    Private Sub LISTAITENS(ByVal path As String)
        Try
            If IO.File.Exists(path) Then
                Using sr As New IO.StreamReader(path)
                    While Not sr.EndOfStream
                        CEDENTEComboBox.Items.Add(sr.ReadLine)
                    End While
                End Using
            Else
                MsgBox("Oooops, Arquivo não encontrado !!!!")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub ATRASOSDataGridView_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ATRASOSDataGridView.CurrentCellChanged
        Try
            If VALORTextBox.Text = "" Or VENCIMENTOMaskedTextBox.Text = "  /  /" Then
            Else
                TextBox1.Text = DateDiff(DateInterval.Day, CType(VENCIMENTOMaskedTextBox.Text, Date), CType(DateValue(Now), Date))
                TJUROS = (TextBox2.Text / 30) * TextBox1.Text
                VJUROS = VALORTextBox.Text * (TJUROS / 100)
                TextBox3.Text = (VALORTextBox.Text / 1) + (VJUROS / 1)
                TextBox3.Text = FormatCurrency(TextBox3.Text)
                Me.ReportViewer1.RefreshReport()
                VALORTextBox.Text = Format(VALORTextBox.Text, "CURRENCY")
            End If
        Catch EX As Exception
            MsgBox("ERRO AO CALCULAR OS JUROS " & EX.ToString)
        End Try
    End Sub
    Private Sub ATRASOS_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If LoginForm3.loginTextBox.Text = "LUIZ" Or LoginForm3.loginTextBox.Text = "JANAINA" Then
            ATRASOSTableAdapter.FillByDATAREP(ATRASOSDataSet.ATRASOS, DateValue(Now))
            If ATRASOSDataSet.Tables(0).Rows.Count > 0 And DateAndTime.Now.Hour < 12 Then
                MsgBox("EXISTE(M) " & ATRASOSDataSet.Tables(0).Rows.Count.ToString & " CHEQUE(S) PARA VERIFICAR REAPRESENTAÇÃO")
            Else
                Me.ATRASOSTableAdapter.FillByTIPOPEN(Me.ATRASOSDataSet.ATRASOS, "LÍQUIDAS")
            End If
        Else
            Me.ATRASOSTableAdapter.FillByTIPOPEN(Me.ATRASOSDataSet.ATRASOS, "LÍQUIDAS")
        End If
        If LoginForm3.loginTextBox.Text = "LUIZ" Then
            Button15.Enabled = True
        Else
            Button15.Enabled = False
        End If
        Try
            If VALORTextBox.Text = "" Or VENCIMENTOMaskedTextBox.Text = "  /  /" Then
            Else
                TextBox1.Text = DateDiff(DateInterval.Day, CType(VENCIMENTOMaskedTextBox.Text, Date), CType(DateValue(Now), Date))
                TJUROS = (TextBox2.Text / 30) * TextBox1.Text
                VJUROS = VALORTextBox.Text * (TJUROS / 100)
                TextBox3.Text = (VALORTextBox.Text / 1) + (VJUROS / 1)
                TextBox3.Text = FormatCurrency(TextBox3.Text)
                Me.ReportViewer1.RefreshReport()
                VALORTextBox.Text = Format(VALORTextBox.Text, "CURRENCY")
            End If
        Catch EX As Exception
            MsgBox("ERRO AO CALCULAR OS JUROS " & EX.ToString)
        End Try
            If NAEMPRESAComboBox.Text = "SIM" Then
                NAEMPRESAComboBox.BackColor = Color.Green
            Else
                NAEMPRESAComboBox.BackColor = Color.White
            End If
            Try
                LISTAITENS("\\SERVIDOR1\Publico Administrativo\Público Administrativo\antigo\CEDENTES.txt")
            Catch EX As Exception
                MsgBox("NÃO FOI POSSÍVEL PREENCHER A COMBOBOX COM OS CEDENTES PORÉM ISSO NÃO IMPACTUA NO FUNCIONAMENTO DO SISTEMA")
            End Try
    End Sub
    Private Sub PRIMEIRO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PRIMEIRO.Click
        ATRASOSBindingSource.MoveFirst()
    End Sub
    Private Sub VOLTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VOLTAR.Click
        ATRASOSBindingSource.MovePrevious()
    End Sub
    Private Sub NOVO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NOVO.Click
        ATRASOSBindingSource.AddNew()
        DATAINCLUMaskedTextBox.Text = DateValue(Now)
        CEDENTEComboBox.Focus()
        TIPOPENComboBox.Text = "LÍQUIDAS"
    End Sub
    Private Sub SALVAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SALVAR.Click
        DATAINCLUMaskedTextBox.Text = DateValue(Now)
        If RichTextBox1.Text = "" Then
            OBSRichTextBox.Text = OBSRichTextBox.Text
        Else
            OBSRichTextBox.Text = OBSRichTextBox.Text + "EM " + DateValue(Now) + " POR " + LoginForm3.loginTextBox.Text + Environment.NewLine + RichTextBox1.Text + Environment.NewLine
        End If
        Try
            ATRASOSBindingSource.EndEdit()
            TableAdapterManager.UpdateAll(ATRASOSDataSet)
            RichTextBox1.Text = ""
        Catch ex As Exception
            MsgBox("ERRO NA ATUALIZAÇÃO DOS DADOS " & ex.ToString)
        End Try
    End Sub
    Private Sub DELETAR_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DELETAR.Click
        If MsgBox("DESEJA REALMENTE DELETAR O REGISTRO", MsgBoxStyle.YesNo, "ATENÇÃO") = MsgBoxResult.Yes Then
            Gravar(CEDENTEComboBox.Text & " " & SACADOTextBox.Text & " " & VALORTextBox.Text & " " & NUMEROTextBox.Text & " DELETADO")
            Me.Validate()
            Try
                ATRASOSBindingSource.RemoveCurrent()
                ATRASOSTableAdapter.Update(ATRASOSDataSet.ATRASOS)
            Catch ex As Exception
                MsgBox("ERRO NA REMOÇÃO DOS DADOS " & ex.ToString)
            End Try
        End If
    End Sub
    Private Sub FRENTE_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FRENTE.Click
        ATRASOSBindingSource.MoveNext()
    End Sub
    Private Sub ULTIMO_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ULTIMO.Click
        ATRASOSBindingSource.MoveLast()
    End Sub
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        ATRASOSTableAdapter.Fill(ATRASOSDataSet.ATRASOS)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If SACADOTextBox.Text = "" Then
            MsgBox("Favor informar nome do sacado", MsgBoxStyle.Information, "Atençao")
        Else
            ATRASOSTableAdapter.FillBySACADO(ATRASOSDataSet.ATRASOS, SACADOTextBox.Text)
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If CEDENTEComboBox.Text = "" Then
            MsgBox("Favor informar nome do cedente", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByCEDENTE(ATRASOSDataSet.ATRASOS, CEDENTEComboBox.Text)
        End If
    End Sub
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If ALINEATextBox.Text = "" Then
            MsgBox("Favor informar alínea", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByALINEA(ATRASOSDataSet.ATRASOS, ALINEATextBox.Text)
        End If
    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If CONTAComboBox.Text = "" Then
            MsgBox("Favor informar a conta", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByCONTA(ATRASOSDataSet.ATRASOS, CONTAComboBox.Text)
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If DATAREPMaskedTextBox.Text = "  /  /" Then
            MsgBox("Favor informar a data da reapresentação", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByDATAREP(ATRASOSDataSet.ATRASOS, DATAREPMaskedTextBox.Text)
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If DATAINCLUMaskedTextBox.Text = "  /  /" Then
            MsgBox("Favor informar a data da inclusão", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByDATAINCLU(ATRASOSDataSet.ATRASOS, DATAINCLUMaskedTextBox.Text)
        End If
    End Sub
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If TIPOComboBox.Text = "" Then
            MsgBox("FAVOR INFORMAR O TIPO", MsgBoxStyle.Information, "ATENÇÃO")
        Else
            ATRASOSTableAdapter.FillByTIPO(ATRASOSDataSet.ATRASOS, TIPOComboBox.Text)
        End If
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If TIPOPENComboBox.Text = "" Then
            MsgBox("Favor informar o tipo de pendência", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByTIPOPEN(ATRASOSDataSet.ATRASOS, TIPOPENComboBox.Text)
        End If
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If VALORTextBox.Text = "" Then
            MsgBox("Favor informar o valor", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByVALOR(ATRASOSDataSet.ATRASOS, VALORTextBox.Text)
        End If
    End Sub
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If NAEMPRESAComboBox.Text = "" Then
            MsgBox("Favor informar estado do cheque", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByNAEMPRESA(ATRASOSDataSet.ATRASOS, NAEMPRESAComboBox.Text)
        End If
    End Sub
    Private Sub Button14_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        If DATAREPMaskedTextBox.Text = "  /  /" Then
            MsgBox("Favor informar data da reapresentação", MsgBoxStyle.Information, "Atenção")
        Else
            ATRASOSTableAdapter.FillByFICHINHA(ATRASOSDataSet.ATRASOS, DATAREPMaskedTextBox.Text)
        End If
    End Sub
    Private Sub OBSRichTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles OBSRichTextBox.TextChanged
        If InStr(OBSRichTextBox.Text, "*") = 1 Then
            OBSRichTextBox.BackColor = Color.Violet
        Else
            OBSRichTextBox.BackColor = Color.White
        End If
    End Sub
    Private Sub ATRASOSDataGridView_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles ATRASOSDataGridView.DataBindingComplete
        Try
            For intx As System.Int32 = 0 To ATRASOSDataGridView.Rows.Count - 1
                Dim tipopendencia As System.String = ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn45").Value.ToString
                If tipopendencia = "LÍQUIDAS" Then
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn45").Style.BackColor = Color.Aquamarine
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn33").Style.BackColor = Color.Aquamarine
                ElseIf tipopendencia = "ACORDO EM ANDAMENTO" Then
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn45").Style.BackColor = Color.Yellow
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn33").Style.BackColor = Color.Yellow
                ElseIf tipopendencia = "PENDÊNCIA EM EXECUÇÃO" Then
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn45").Style.BackColor = Color.OrangeRed
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn33").Style.BackColor = Color.OrangeRed
                End If
                Dim COROBS As System.String = ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn46").Value.ToString
                If InStr(COROBS, "*") = 1 Then
                    ATRASOSDataGridView.Rows(intx).Cells("DataGridViewTextBoxColumn46").Style.BackColor = Color.Violet
                End If
            Next
            Label4.Text = "Total de : " & ATRASOSDataGridView.Rows.Count & " registros"
        Catch ex As Exception
            MsgBox("ERRO AO COLORIR AS LINHAS ", ex.ToString)
        End Try
    End Sub
    Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyCode = 13 Then
            Try
                If VALORTextBox.Text = "" Or VENCIMENTOMaskedTextBox.Text = "  /  /" Then
                Else
                    TextBox1.Text = DateDiff(DateInterval.Day, CType(VENCIMENTOMaskedTextBox.Text, Date), CType(DateValue(Now), Date))
                    TJUROS = (TextBox2.Text / 30) * TextBox1.Text
                    VJUROS = VALORTextBox.Text * (TJUROS / 100)
                    TextBox3.Text = (VALORTextBox.Text / 1) + (VJUROS / 1)
                    TextBox3.Text = FormatCurrency(TextBox3.Text)
                    Me.ReportViewer1.RefreshReport()
                    VALORTextBox.Text = Format(VALORTextBox.Text, "CURRENCY")
                End If
            Catch EX As Exception
                MsgBox("ERRO AO CALCULAR OS JUROS " & EX.ToString)
            End Try
        End If
    End Sub
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Dim CalForm As New Form
        Dim Cal As New MonthCalendar
        Cal.MaxSelectionCount = 1
        CalForm.Controls.Add(Cal)
        CalForm.ClientSize = Cal.Size
        CalForm.Height += 24
        CalForm.Width += 50
        CalForm.MinimizeBox = False
        CalForm.MaximizeBox = False
        CalForm.MinimumSize = CalForm.Size
        CalForm.MaximumSize = CalForm.Size
        CalForm.ShowDialog()
        DATAREPMaskedTextBox.Text = Cal.SelectionRange.Start.ToString
        ATRASOSTableAdapter.FillByDATAREP(ATRASOSDataSet.ATRASOS, DATAREPMaskedTextBox.Text)
        CalForm.Close()
        CalForm.Dispose()
        CalForm = Nothing
        Cal.Dispose()
        Cal = Nothing
    End Sub
    Private Sub TIPOComboBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TIPOComboBox.LostFocus
        If TIPOComboBox.Text = "DPL" Then
            ALINEATextBox.Enabled = False
            BORDEROTextBox.Enabled = False
        Else
            ALINEATextBox.Enabled = True
            BORDEROTextBox.Enabled = True
        End If
    End Sub
    Private Sub REAPRESENTADOComboBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles REAPRESENTADOComboBox.LostFocus
        If REAPRESENTADOComboBox.Text = "NÃO" Then
            DATAREPMaskedTextBox.Enabled = False
        Else
            DATAREPMaskedTextBox.Enabled = True
        End If
    End Sub
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Try
            If VALORTextBox.Text = "" Or VENCIMENTOMaskedTextBox.Text = "  /  /" Then
            Else
                TextBox1.Text = DateDiff(DateInterval.Day, CType(VENCIMENTOMaskedTextBox.Text, Date), CType(DateValue(Now), Date))
                TJUROS = (TextBox2.Text / 30) * TextBox1.Text
                VJUROS = VALORTextBox.Text * (TJUROS / 100)
                TextBox3.Text = (VALORTextBox.Text / 1) + (VJUROS / 1)
                TextBox3.Text = FormatCurrency(TextBox3.Text)
                Me.ReportViewer1.RefreshReport()
                VALORTextBox.Text = Format(VALORTextBox.Text, "CURRENCY")
            End If
        Catch EX As Exception
            MsgBox("ERRO AO CALCULAR OS JUROS " & EX.ToString)
        End Try
    End Sub
    Private Sub NAEMPRESAComboBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NAEMPRESAComboBox.TextChanged
        If NAEMPRESAComboBox.Text = "SIM" Then
            NAEMPRESAComboBox.BackColor = Color.Green
        Else
            NAEMPRESAComboBox.BackColor = Color.White
        End If
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        ATRASOSTableAdapter.FillByFALTANDO(ATRASOSDataSet.ATRASOS, CEDENTEComboBox.Text, NAEMPRESAComboBox.Text, CONTAComboBox.Text, REAPRESENTADOComboBox.Text)
    End Sub
End Class